<?php

namespace app\admin\controller;

use app\Request;
use think\facade\Db;

class Controller extends \app\BaseController
{
    protected $admin = null;

    protected function initialize()
    {
        $admin = \app\common\facade\auth\Auth::attempt(input());

        if (empty($admin)) {
            $this->showError('登录失败，请重新登录');
        }

        $this->admin = $admin;
    }

    private function showError($message)
    {
        exit(json_encode([
            'code' => 401,
            'message' => $message,
            'data' => [],
        ], JSON_UNESCAPED_UNICODE));
    }

    protected function getPaginate($page = 'page', $listrows = 'list_rows', $request = null)
    {
        !$request && $request = request();
        $paginate = $request->only([$page => 1, $listrows => 10]);
        $paginate[$page] = $paginate[$page] ? $paginate[$page] : 1;
        $paginate[$listrows] = $paginate[$listrows] ? $paginate[$listrows] : 10;

        return $paginate;
    }
}
